package com.banyuan.filter;

import javax.servlet.*;
import java.io.IOException;

public class CharcterFilter implements Filter {

    private String encoding;
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
         encoding = filterConfig.getInitParameter("encoding");

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
                servletRequest.setCharacterEncoding(encoding);
                servletResponse.setCharacterEncoding(encoding);
                servletResponse.setContentType("text/html"+encoding);
                filterChain.doFilter(servletRequest,servletResponse);  //  放行
    }

    @Override
    public void destroy() {

    }
}
